#include <pthread.h>


class Mutex{
public:
    Mutex(pthread_mutex_t* lock):_lock(lock){}
    ~Mutex(){}

    //上锁
    void Lock(){
        pthread_mutex_lock(_lock);
    }

    //解锁
    void UnLock(){
        pthread_mutex_unlock(_lock);
    }
private:
    pthread_mutex_t* _lock;
};

class MutexGuard{
public:
    //RAII初始化上锁
    MutexGuard(pthread_mutex_t* lock):_mutex(lock){
        _mutex.Lock();
    }

    //析构后解锁
    ~MutexGuard(){
        _mutex.UnLock();
    }
    
private:
    Mutex _mutex;
};